<?php

namespace App\Http\Controllers\Common;
use App\Http\Requests\Common\Captcha\SmsCodeRequest;
use Illuminate\Http\Request;
use Illuminate\Hashing\BcryptHasher as Hasher;
use Cache;


class AjaxCodeController extends CommonController{

    protected $hasher;
    public function __construct(Hasher $hasher){
        $this->hasher = $hasher;
    }
    /**
     * ajax验证验证码
     * @param Request $request
     */
    public function ajaxCode(Request $request){
        $code = strtolower($request->input('code'));
        $captcha = session('captcha.key');
        //验证哈希验证码
        echo ($this->hasher->check($code, $captcha)) ? 'true' : 'false';
    }
    /**
     * 短信验证获取请求
     * @param Request $request
     */
    public function smsCode(Request $request){
        $mobCode = $request->input('mobCode');
        $mobile = $request->input('mobile');
        //判断手机是不是被注册
        echo ($mobCode == session('mobile_verification_code') && $mobile == session('mobile_verification')) ? 'true' : 'false';
    }
}